<template>
  <div class='manage-ig'>
    <p class="title">{{title}} 
      <el-button v-for="(item,index) in btnsData" :key="index" :type="item.type" :disabled="!item.canUse" class="btn-add fr" @click="item.click(index)">{{item.label}}</el-button>
    </p>
    <div class="table-box">
      <Table :modelData="modelData" :listData="listData" :pageInfo="pageInfo"></Table>
    </div>
  </div>
</template>
<script>
import Table from '../../components/table'
export default {
  components: {Table},
  name: "",
  data() {
    return {
      title:"议题评分管理",
      btnsData:[
        {label:"开启",type:'success',click:this.start,canUse:false},
        {label:"停止",type:'danger',click:this.end,canUse:false},
      ],
      modelData:[
        {myType:'index',label:"序号"},
        {myType:'normal',prop:"topicName",label:'议题名称'},
        {myType:'normal',prop:"userName",label:'组长信息'},
        {myType:'normal',prop:"score",label:'评分'},
        {myType:'normal',prop:"endScore",label:'总分'},
        {myType:'operate',label:'管理',btns:[
          {label:'编辑',click:this.edit,icon:require('../../assets/images/manageHome/edit.png')},
          // {label:'删除',click:this.delete,icon:require('../../assets/images/manageIssues/delete.png')}
        ],width:"100"}
      ],
      listData:[],
      pageInfo:{
        page:1,
        total:10,
        size:10,
        changePage:this.changePage
      }
    };
  },
  methods: {
    // 开始
    start(){
      // console.log("开始")
      _g.apiPost('topicPoint/updateTopicStatusStart.do').then(res=>{
        _g.toMessage(res)
        if(!res.status)this.btnsData.forEach((ele,index)=>{
          ele.canUse=index==1
        })
      })
    },
    // 停止
    end(){
      _g.apiPost('topicPoint/updateTopicStatusClose.do').then(res=>{
        _g.toMessage(res)
        if(!res.status)this.btnsData.forEach((ele,index)=>{
          ele.canUse=index==0
        })
      })
    },
    
    // 新增
    add() {
      this.$store.state.add.show = true;
    },
    edit(scope) {
      if(!this.btnsData[1].canUse){
        _g.toMessage({status:1,msg:"未开启评分"})
        return
      }
      this.$store.state.add.show = true;
      this.$store.state.add.info=JSON.parse(JSON.stringify(scope.row))
      this.$store.state.add.OK=this.saveEdit
    },
    saveEdit(){
      var params={
        userId:this.$store.state.add.info.userId,
        topicId:this.$store.state.add.info.id
      }
      _g.apiPost('topicPoint/saveLeader.do',params).then(res=>{
        _g.toMessage(res)
        if(!res.error){
          this.getListData()
          socket_topic.send('display')
        }
      })
    },
    // 删除
    delete(scope) {
      this.$store.state.confirmInfo.message = "是否确认删除？";
      this.$store.state.confirmInfo.show = true;
    },
    // 翻页
    changePage() {
      this.getListData()
    },

    getListData(){
      var params={
        currPageNo:this.pageInfo.page
      }
      _g.apiPost('topicPoint/getTopicPointList.do',params).then(res=>{
        if(res.status==1){
          _g.toMessage(res)
          return
        }
        this.pageInfo.total=res.data.data.total
        this.$set(this,'listData',res.data.data.list)
        this.btnsData.forEach((ele,index)=>{
          ele.canUse=index==res.data.statusTopic
        })
      })
    },
    getSelectData(){
      _g.apiPost('topicPoint/selectLeaderList.do').then(res=>{
        this.$set(this.$store.state.selectData.headersList,'data',res.data)
      })
      // this.$store.state.selectData.headersList.settime.settime=setInterval(()=>{

      // },this.$store.state.selectData.headersList.settime.time*1000)
    }
  },
  created() {
    this.getListData()
    this.getSelectData()
  }
};
</script>
<style lang="scss" scoped>
.manage-ig {
  width: 100%;
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
  overflow: auto;

  .title {
    font-weight: 600;
    font-size: 20px;
    background-color: #fff;
    text-indent: 20px;
    height: 60px;
    line-height: 60px;
    box-sizing: border-box;
    border-bottom: 1px solid #ebeef5;
  }
  .table-box {
    height: calc(100% - 60px);
  }
}
</style>